package org.demo.pattern.factory;

import java.util.HashMap;

/**
 * 
 * @author  
 * @date    2011-5-20
 * @file    org.demo.pattern.factory.Factory.java
 */
public class Factory {
	
	private static HashMap<String,Object> pool = new HashMap<String, Object>();
	
	@SuppressWarnings("unchecked")
	public static <T> T getInstance(String key, Class<T> cls){
		T obj = (T)pool.get(key);		
		if (obj == null){
			try {
				obj = cls.newInstance();
				pool.put(key, obj);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return obj;
	}
}
